package com.lovely3x.versionchecklibrary;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;

import com.lovely3x.common.activities.CommonActivity;
import com.lovely3x.common.versioncontroller.Version;
import com.lovely3x.common.versioncontroller.impls.ClickNotificationToInstallActivity;

import java.io.File;

/**
 * 静默下载完成提示界面
 * Created by lovely3x on 16-2-20.
 */
public class SilentDownloadedActivity extends CommonActivity {

    public static final String EXTRA_VERSION = "extra.version.obj";
    public static final String EXTRA_DOWNLOADED_FILE_PATH = "extra.downloaded.file.path";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        //远程版本对象
        Version remoteVersion = intent.getParcelableExtra(EXTRA_VERSION);
        //文件保存位置
        final String downloadedPath = intent.getStringExtra(EXTRA_DOWNLOADED_FILE_PATH);
        new AlertDialog.Builder(this)
                .setTitle(R.string.new_version_already_downloaded)
                .setMessage(remoteVersion.getDescription())
                .setNegativeButton(R.string.cancel, null)
                .setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ClickNotificationToInstallActivity.launchMe(SilentDownloadedActivity.this, new File(downloadedPath));
                    }

                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        })
                .show();
    }
}
